

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>用户管理</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-fluid">   
    <div class="layui-card">
      
      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button class="layui-btn layuiadmin-btn-admin" data-type="add">添加业务标签</button>
        </div>
        <table id="LAY-user-back-manage" lay-filter="LAY-user-back-manage"></table>
        <script type="text/html" id="table-leaf-update">
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>修改</a>
        </script>
      </div>
    </div>
  </div>

 <script src="../../../layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'leaf', 'table'], function(){
    var $ = layui.$
    ,form = layui.form
    ,table = layui.table;

  
    //事件
    var active = {
      add: function(){
        layer.open({
          type: 2
          ,title: '添加业务标签'
          ,content: 'add.html'
          ,area: ['420px', '420px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            var form1 = window['layui-layer-iframe'+ index].layui.form
            ,submitID = 'LAY-user-back-submit'
            ,submit1 = layero.find('iframe').contents().find('#'+ submitID);
            //监听提交
            form1.on('submit(LAY-user-front-submit)', function(data){
              var field = data.field; //获取提交的字段
              //提交 Ajax 成功后，静态更新表格中的数据
              $.ajax({
                url:"/api/leaf",
                type:"POST",
                dataType:"JSON",
                data:JSON.stringify(field),
                contentType: 'application/json',
                success:function(obj){
                    layer.msg("添加成功")
                    table.reload('LAY-user-front-submit'); //数据刷新
                    table.reload('LAY-user-back-manage'); //数据刷新
                    layer.close(index); //关闭弹层
                },
                error:function(obj){
                  layer.msg(obj.responseJSON.message)
                }
              });

            });

            submit1.trigger('click');
          }
        }); 
      }
    }  
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  });
  </script>
</body>
</html>

